{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                  \n",
      "        *         \n",
      "        **        \n",
      "       ***        \n",
      "       ****       \n",
      "      *****       \n",
      "      ******      \n",
      "      *****       \n",
      "       ****       \n",
      "       ***        \n",
      "        **        \n",
      "        *         \n"
     ]
    }
   ],
   "source": [
    "n=int(input('输入一个整数:'))\n",
    "for i in range(n):\n",
    "    print(('*'*i).center(n*3))#center()是字符串排版方法，居中对齐\n",
    "                              #其中的参数n*3表示排版后字符串长度\n",
    "for i in range(n,0,-1):\n",
    "    print(('*'*i).center(n*3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "14\n",
      "21\n",
      "28\n",
      "42\n",
      "49\n",
      "56\n",
      "63\n",
      "77\n",
      "84\n",
      "91\n",
      "98\n"
     ]
    }
   ],
   "source": [
    "for i in range(1, 101):\n",
    "    if i % 7 == 0 and i % 5 != 0:\n",
    "        print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 24]\n"
     ]
    }
   ],
   "source": [
    "def demo(s):\n",
    "    result = [0, 0]\n",
    "    for ch in s:\n",
    "        if ch.islower():  # 当前字符为小写字母\n",
    "            result[1] += 1  # 小写字母个数加1\n",
    "        elif ch.isupper():  # 当前字符为大写字母\n",
    "            result[0] += 1  # 大写字母个数加1\n",
    "    return result\n",
    "\n",
    "print(demo('Beautiful is better than ugly'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def yanghui(t):\n",
    "    if t <= 0:\n",
    "        return []\n",
    "    print([1])  # 输出第一行\n",
    "    line = [1, 1]\n",
    "    print(line)  # 输出第二行\n",
    "    for i in range(2, t):\n",
    "        r = []  # 存档当前行除两端之外的数字\n",
    "        for j in range(0, len(line) - 1):\n",
    "            r.append(line[j] + line[j + 1])  # 第i行除两端之外的其他的数字\n",
    "        line = [1] + r + [1]  # 第i行的全部数字\n",
    "        print(line)  # 输出第i行\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 5\n"
     ]
    }
   ],
   "source": [
    "x=input('Input two numbers: ')#input()函数返回字符串\n",
    "a,b=map(int,x.split())#split()方法使用空格对字符串进行切分\n",
    "if a>b:\n",
    "    a,b=b,a#序列解包，交换两个变量的值\n",
    "    print(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def femo(n):\n",
    "    def isPrime(p):\n",
    "        if p == 2:\n",
    "            return True\n",
    "        if p % 2 == 0:\n",
    "            return False\n",
    "        for i in range(3, int(p ** 0.5) + 1, 2):\n",
    "            if p % i == 0:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "    if isinstance(n, int) and n > 0 and n % 2 == 0:\n",
    "        for i in range(2, n // 2 + 1):\n",
    "            if isPrime(i) and isPrime(n - i):\n",
    "                print(i, '+', n - i, '=', n - 1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.95\n"
     ]
    }
   ],
   "source": [
    "def rate(origin, userInput):\n",
    "    if not (isinstance(origin, str) and isinstance(userInput, str)):\n",
    "        print('The two parameters must be strings.')\n",
    "        return\n",
    "    #统计对应位置上打对的字符数量\n",
    "    right = sum((1 for o, u in zip(origin, userInput) if o == u))\n",
    "    return round(right / len(origin), 2)\n",
    "\n",
    "s1 = 'Readability counts.'\n",
    "s2 = 'readability counts.'\n",
    "print(rate(s1, s2))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
